package biz

import (
	"context"
	pb "digitalhuman/api/user/v1"
	"digitalhuman/models"
	"github.com/go-kratos/kratos/v2/log"
)

// UserRepo is a User repo.
type UserRepo interface {
	Update(context.Context, *models.User) (*models.User, error)
	FindByID(context.Context, int) (*models.User, error)
	FindByUserName(context.Context, string) (*models.User, error)
	GenerateTokenAndSave(c *models.User, secret string) (string, error)
	Register(ctx context.Context, u *pb.RegisterRequest) (*models.User, error)
	GetDouYinShareUrl(ctx context.Context, u *pb.DouYinShareRequest) (string, error)
	VerifyCode(ctx context.Context, p *pb.GetVerifyCodeReq) error
}

// UserBiz is a User usecase.
type UserBiz struct {
	UserData UserRepo
	log      log.Logger
}

// NewUserBiz NewGreeterUsecase new a Greeter usecase.
func NewUserBiz(repo UserRepo, logger log.Logger) *UserBiz {
	return &UserBiz{UserData: repo, log: logger}
}

func (uc *UserBiz) UpdateUser(ctx context.Context, u *models.User) (*models.User, error) {
	return uc.UserData.Update(ctx, u)
}

func (uc *UserBiz) FindUserById(ctx context.Context, userId int) (*models.User, error) {
	return uc.UserData.FindByID(ctx, userId)
}

func (uc *UserBiz) FindByUserName(ctx context.Context, userName string) (*models.User, error) {
	return uc.UserData.FindByUserName(ctx, userName)
}

func (uc *UserBiz) GenerateTokenAndSave(c *models.User, secret string) (string, error) {
	return uc.UserData.GenerateTokenAndSave(c, secret)
}

func (uc *UserBiz) Register(ctx context.Context, u *pb.RegisterRequest) (*models.User, error) {
	return uc.UserData.Register(ctx, u)
}

func (uc *UserBiz) GetDouYinShareUrl(ctx context.Context, u *pb.DouYinShareRequest) (string, error) {
	return uc.UserData.GetDouYinShareUrl(ctx, u)
}

func (uc *UserBiz) VerifyCode(ctx context.Context, u *pb.GetVerifyCodeReq) error {
	return uc.UserData.VerifyCode(ctx, u)
}
